package com.atguigu.tingshu.album.api;

import com.atguigu.tingshu.album.service.BaseCategoryService;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.common.result.ResultCodeEnum;
import com.atguigu.tingshu.model.album.BaseAttribute;
import com.atguigu.tingshu.model.album.BaseCategory3;
import com.atguigu.tingshu.model.album.BaseCategoryView;
import com.atguigu.tingshu.vo.album.AlbumCategoryVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@Tag(name = "分类管理")
@RestController
@RequestMapping(value = "/api/album/category")
@SuppressWarnings({"unchecked", "rawtypes"})
public class BaseCategoryApiController {

    @Autowired
    private BaseCategoryService baseCategoryService;


    @Operation(summary = "分类数据查询接口")
    @GetMapping("/getBaseCategoryList")
    public Result<List<AlbumCategoryVo>> getBaseCategoryList() {
        List<AlbumCategoryVo> albumCategoryVoList = baseCategoryService.getBaseCategoryList();
//		return Result.ok(albumCategoryVoList);
        return Result.build(albumCategoryVoList, ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "根据1级分级分类id查询专辑的属性和属性值")
    @GetMapping("/findAttribute/{category1Id}")
    public Result<List<BaseAttribute>> findAttributeByCategoryId(@PathVariable(value = "category1Id") Integer category1Id) {
        List<BaseAttribute> baseAttributeList = baseCategoryService.findAttributeByCategoryId(category1Id);
        return Result.ok(baseAttributeList);
    }



    @Operation(summary = "根据三级分类id查询")
    @GetMapping("/getCategoryView/{category3Id}")
    public Result<BaseCategoryView> findCategoryInfoByC3Id(@PathVariable(value = "category3Id") Long category3Id) {
        BaseCategoryView baseCategoryView = baseCategoryService.findCategoryInfoByC3Id(category3Id);
        return Result.ok(baseCategoryView);
    }


    @Operation(summary = "根据1级分类id查询分类信息")
    @GetMapping("getBaseCategoryList/{category1Id}")
    public Result<AlbumCategoryVo> getBaseCategoryList(@PathVariable(value = "category1Id") Long category1Id) {
        AlbumCategoryVo albumCategoryVo = baseCategoryService.getAllCategoryList(category1Id);
        return Result.ok(albumCategoryVo);
    }

    @Operation(summary = "根据1级分类id查询三级分类信息")
    @GetMapping("findTopBaseCategory3/{category1Id}")
    public Result<List<BaseCategory3>> findTopBaseCategory3(@PathVariable Long category1Id) {
        List<BaseCategory3> baseCategory3List = baseCategoryService.findTopBaseCategory3(category1Id);
        return Result.ok(baseCategory3List);
    }
}

